home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / var / lib / dpkg / info / libpam0g.postinst < prev    next >
Text File  |  2008-10-16  |  6KB  |  237 lines

  1. #!/bin/bash
  2.  
  3. # postinst based heavily on the postinst of libssl0.9.8, courtesy of 
  4. # Christoph Martin.
  5.  
  6. . /usr/share/debconf/confmodule
  7.  
  8. set -e
  9.  
  10. # element() is a helper function for file-rc:
  11. element() {
  12.     local element list IFS
  13.  
  14.     element="$1"
  15.  
  16.     [ "$2" = "in" ] && shift
  17.     list="$2"
  18.     [ "$list" = "-" ] && return 1
  19.     [ "$list" = "*" ] && return 0
  20.  
  21.     IFS=","
  22.     set -- $list
  23.     case $element in
  24.     "$1"|"$2"|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$9")
  25.         return 0
  26.     esac
  27.     return 1
  28. }
  29.  
  30. # filerc (runlevel, service) returns /etc/init.d/service, if service is
  31. # running in $runlevel:
  32. filerc() {
  33.     local runlevel basename
  34.     runlevel=$1
  35.     basename=$2
  36.     while read LINE
  37.     do
  38.     case $LINE in
  39.         \#*|"") continue
  40.     esac
  41.  
  42.     set -- $LINE
  43.     SORT_NO="$1"; STOP="$2"; START="$3"; CMD="$4"
  44.     [ "$CMD" = "/etc/init.d/$basename" ] || continue
  45.  
  46.     if element "$runlevel" in "$START" || element "S" in "$START"
  47.     then
  48.         echo "/etc/init.d/$basename"
  49.         return 0
  50.     fi
  51.     done < /etc/runlevel.conf
  52.     echo ""
  53. }
  54.  
  55. installed_services() {
  56.     check="$@"
  57.  
  58.     # Only get the ones that are installed, and configured
  59.     check=$(dpkg -s $check 2> /dev/null | egrep '^Package:|^Status:' | awk '{if ($1 ~ /^Package:/) { package=$2 } else if ($0 ~ /^Status: .* installed$/) { print package }}')
  60.  
  61.     # some init scripts don't match the package names
  62.     check=$(echo $check | \
  63.     sed -e's/\bapache2-common\b/apache2/g' \
  64.         -e's/\bat\b/atd/g' \
  65.         -e's/\bdovecot-common\b/dovecot/g' \
  66.         -e's/\bdante-server\b/danted/g' \
  67.         -e's/\bexim4-base\b/exim4/g' \
  68.         -e's/\bheartbeat-2\b/heartbeat/g' \
  69.         -e's/\bhylafax-server\b/hylafax/g' \
  70.         -e's/\bpartimage-server\b/partimaged/g' \
  71.         -e's/\bsasl2-bin\b/saslauthd/g' \
  72.     )
  73.  
  74.     for service in $check; do
  75.     if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
  76.        idl=$(ls /etc/init.d/${service} 2> /dev/null | head -n 1)
  77.        if [ -n "$idl" ] && [ -x $idl ]; then
  78.         services="$service $services"
  79.        else
  80.         echo "WARNING: init script for $service not found." >&2
  81.        fi
  82.     else
  83.         if [ -f /usr/share/file-rc/rc ] || [ -f /usr/lib/file-rc/rc ] && [ -f /etc/runlevel.conf ]; then
  84.         idl=$(filerc $rl $service)
  85.         else
  86.         idl=$(ls /etc/rc${rl}.d/S??${service} 2> /dev/null | head -n 1)
  87.         fi
  88.         if [ -n "$idl" ] && [ -x $idl ]; then
  89.             services="$service $services"
  90.         fi
  91.     fi
  92.     done
  93.     echo "$services"
  94. }
  95.  
  96. if [ "$1" = "configure" ]
  97. then
  98.     if [ ! -z "$2" ]; then
  99.     if dpkg --compare-versions "$2" lt 0.99.10.0; then
  100.         db_version 2.0
  101.  
  102.         echo -n "Checking for services that may need to be restarted..."
  103.  
  104.         check="apache2-common at bayonne cherokee courier-authdaemon"
  105.         check="$check cron cups"
  106.         check="$check dante-server diald dovecot-common exim exim4-base"
  107.         check="$check fcron fireflier-server freeradius gdm heartbeat"
  108.         check="$check heartbeat-2 hylafax-server iiimf-server inn2"
  109.         check="$check kannel linesrv linesrv-mysql lsh-server"
  110.         check="$check muddleftpd netatalk nuauth partimage-server"
  111.         check="$check perdition pgpool popa3d postgresql-7.4"
  112.         check="$check postgresql-8.1 postgresql-8.2 proftpd pure-ftpd"
  113.         check="$check pure-ftpd-ldap pure-ftpd-mysql"
  114.         check="$check pure-ftpd-postgresql racoon samba sasl2-bin"
  115.         check="$check sfs-server solid-pop3d squid squid3 tac-plus"
  116.         check="$check vsftpd wu-ftpd wzdftpd xrdp yardradius yaws"
  117.  
  118.         if ! who | awk '{print $2}'|grep -q ':[0-9]'; then
  119.         check="$check kdm wdm xdm"
  120.         fi
  121.  
  122.         echo "Checking init scripts..."
  123.         services=$(installed_services "$check")
  124.         if [ -n "$services" ]; then
  125.         db_reset libpam0g/restart-services
  126.         db_set libpam0g/restart-services "$services"
  127.         question_priority="critical"
  128.         # Do not prompt when we're running in the upgrade-manager
  129.         # and only default services need restarting.
  130.         nondefault_services=$(echo "$services" | sed \
  131.             -e's/\batd\b//g' \
  132.             -e's/\bcron\b//g' \
  133.             -e's/\bcups\b//g' \
  134.             -e's/\bgdm\b//g' \
  135.             -e's/\bkdm\b//g' \
  136.             -e's/\bsamba\b//g' \
  137.             -e's/^ *//g')
  138.         if [ -n "$RELEASE_UPGRADE_IN_PROGRESS" ] && [ -z "$nondefault_services" ]; then
  139.             question_priority="medium"
  140.         fi
  141.         db_input "$question_priority" libpam0g/restart-services || true
  142.         db_go || true
  143.         db_get libpam0g/restart-services
  144.  
  145.         if [ "x$RET" != "x" ]
  146.         then
  147.             services=$RET
  148.         else
  149.             services=""
  150.         fi
  151.         echo
  152.         if [ "$services" != "" ]; then
  153.             echo "Restarting services possibly affected by the upgrade:"
  154.             failed=""
  155.             rl=$(runlevel | sed 's/.*\ //')
  156.             for service in $services; do
  157.             if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
  158.                 idl="invoke-rc.d ${service}"
  159.             elif [ -f /usr/share/file-rc/rc ] || [ -f /usr/lib/file-rc/rc ] && [ -f /etc/runlevel.conf ]; then
  160.                 idl=$(filerc $rl $service)
  161.             else
  162.                 idl=$(ls /etc/rc${rl}.d/S??${service} 2> /dev/null | head -n 1)
  163.             fi
  164.  
  165.             case "$service" in
  166.                 gdm)
  167.                 echo -n "  $service: reloading..."
  168.                 if $idl reload > /dev/null 2>&1; then
  169.                     echo "done."
  170.                 else
  171.                     echo "FAILED! ($?)"
  172.                     failed="$service $failed"
  173.                 fi
  174.                 continue
  175.                 ;;
  176.             esac
  177.             echo -n "  $service: stopping..."
  178.             $idl stop > /dev/null 2>&1 || true
  179.             sleep 1
  180.             echo -n "starting..."
  181.             if $idl start > /dev/null 2>&1; then
  182.                 echo "done."
  183.             else
  184.                 echo "FAILED! ($?)"
  185.                 failed="$service $failed"
  186.             fi
  187.             done
  188.             echo
  189.             if [ -n "$failed" ]; then
  190.             db_subst libpam0g/restart-failed services "$failed"
  191.             db_input critical libpam0g/restart-failed || true
  192.             db_go || true
  193.             else
  194.             echo "Services restarted successfully."
  195.             fi
  196.             echo
  197.         fi
  198.         else
  199.         echo "Nothing to restart."
  200.         fi
  201.  
  202.         if who | awk '{print $2}' | grep -q ':[0-9]'; then
  203.         dms=""
  204.         for service in kdm wdm xdm; do
  205.             case "$services" in
  206.             *$service*)    ;;
  207.             *)    dms="$dms $service"
  208.             esac
  209.         done
  210.         services=$(installed_services "$dms")
  211.         if [ -n "$services" ]; then
  212.             if [ -n "$RELEASE_UPGRADE_IN_PROGRESS" ] \
  213.                && [ -x /usr/share/update-notifier/notify-reboot-required ]
  214.             then
  215.             /usr/share/update-notifier/notify-reboot-required
  216.             else
  217.             db_input critical libpam0g/xdm-needs-restart || true
  218.             db_go || true
  219.             fi
  220.         fi
  221.         fi
  222.  
  223.         # Shut down the frontend, to make sure none of the
  224.         # restarted services keep a connection open to it
  225.         db_stop
  226.     fi # end upgrading and $2 lt 0.99.10.0
  227.     fi # Upgrading
  228. fi
  229.  
  230. # Automatically added by dh_makeshlibs
  231. if [ "$1" = "configure" ]; then
  232.     ldconfig
  233. fi
  234. # End automatically added section
  235.  
  236.  
  237.